//
//  PicCell.m
//  TQProduction
//
//  Created by Davy on 2017/5/18.
//  Copyright © 2017年 Lvrulan. All rights reserved.
//

#import "PostPicCell.h"


@interface PostPicCell ()

@property (nonatomic, strong) UIImageView *imageView;
@property (nonatomic, strong) UIButton *deleteBtn;

@end

@implementation PostPicCell

-(instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        _imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height)];
        _imageView.clipsToBounds = YES;
        _imageView.backgroundColor = [UIColor colorWithHexString:@"#f6f6f6" andAlpha:1];
        _imageView.contentMode = UIViewContentModeScaleAspectFill;
        [self.contentView addSubview:_imageView];
        
        _deleteBtn = [[UIButton alloc] initWithFrame:CGRectMake(frame.size.width-24, 4, 20, 20)];
        [_deleteBtn addTarget:self action:@selector(deletePic) forControlEvents:UIControlEventTouchUpInside];
        [self.contentView addSubview:_deleteBtn];
        [_deleteBtn setBackgroundImage:[UIImage imageNamed:@"postDeleteImage"] forState:UIControlStateNormal];
    }
    return self;
}

-(void)setImage:(UIImage *)image{
    if(image){
        _image = image;
        _deleteBtn.hidden = NO;
        _imageView.image = image;
        _imageView.contentMode = UIViewContentModeScaleAspectFill;
    }else{
        _imageView.image = [UIImage imageNamed:@"addPic"];
        _imageView.contentMode = UIViewContentModeCenter;
        _deleteBtn.hidden = YES;
    }
}


-(void)deletePic{
    if ([self.delegate respondsToSelector:@selector(deletePic:)]) {
        [self.delegate deletePic:self.image];
    }
}
@end
